package org.roger.similarity;

import org.apache.lucene.search.similarities.BasicStats;
import org.apache.lucene.search.similarities.Normalization;
import org.apache.lucene.search.similarities.NormalizationH1;
import org.apache.lucene.search.similarities.SimilarityBase;

public class BoostingSimilarity extends SimilarityBase{
	protected final Normalization normalization;
	
	public BoostingSimilarity(Normalization normalization){
		this.normalization = normalization;
	}
	public BoostingSimilarity(){
		this.normalization = new NormalizationH1();
	}
	@Override
	protected float score(BasicStats stats, float freq, float docLen) {
		float tfn = normalization.tfn(stats, freq, docLen);
		return stats.getBoost() * tfn;
	}

	@Override
	public String toString() {
		return (new StringBuilder()).append("BoostingSimilarity ").append(normalization.toString())
				.toString();
	}

}
